package com.ruoyi.project.configureSystem.controller;

import java.util.List;

import com.ruoyi.framework.tree.TreeUtils;
import com.ruoyi.project.configureSystem.domain.SysNode;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.configureSystem.domain.CCompany;
import com.ruoyi.project.configureSystem.service.ICCompanyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 公司信息Controller
 *
 * @author wangshuo
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/configureSystem/company")
public class CCompanyController extends BaseController
{
    @Autowired
    private ICCompanyService cCompanyService;
    @Autowired
    private TreeUtils treeUtils;

    /**
     * 查询公司信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:list')")
    @GetMapping("/list")
    public AjaxResult list(CCompany cCompany)
    {
        List<CCompany> list = cCompanyService.selectCCompanyList(cCompany);
        return AjaxResult.success(list);
    }

    /**
     * 查询公司信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:treeSelect')")
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(CCompany cCompany)
    {
        List<SysNode> list = cCompanyService.selectCCompanyNodeList(cCompany);
        return AjaxResult.success(treeUtils.buildTreeSelect(list));
    }

    /**
     * 导出公司信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:export')")
    @Log(title = "公司信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CCompany cCompany)
    {
        List<CCompany> list = cCompanyService.selectCCompanyList(cCompany);
        ExcelUtil<CCompany> util = new ExcelUtil<CCompany>(CCompany.class);
        return util.exportExcel(list, "company");
    }

    /**
     * 获取公司信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cCompanyService.selectCCompanyById(id));
    }

    /**
     * 新增公司信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:add')")
    @Log(title = "公司信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CCompany cCompany)
    {
        return toAjax(cCompanyService.insertCCompany(cCompany));
    }

    /**
     * 修改公司信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:edit')")
    @Log(title = "公司信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CCompany cCompany)
    {
        return toAjax(cCompanyService.updateCCompany(cCompany));
    }

    /**
     * 删除公司信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:company:remove')")
    @Log(title = "公司信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cCompanyService.deleteCCompanyByIds(ids));
    }
}
